package com.sms.shared;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.user.client.rpc.IsSerializable;

//	import net.sf.gilead.pojo.java5.LightEntity;

public class SessionInfo implements java.io.Serializable, IsSerializable {
	// private static final long serialVersionUID = 1111222233335555L;

	/**
		 * 
		 */
	private static final long serialVersionUID = 1L;
	/**
		 * 
		 */
	// private static final long serialVersionUID = -5650872352638414387L;
	public static final String JSESSION_ID = "JSESSION_ID";
	public static final String SESSION_IP_ADDRESS = "SESSION_IP_ADDRESS";
	public static final String SESSION_PARTYID = "SESSION_PARTYID";
	public static final String SESSION_PARTYNAME = "SESSION_PARTYNAME";

	public static final String SESSION_USERNAME = "SESSION_USERNAME";
	public static final String SESSION_EMAIL = "SESSION_EMAIL";
	public static final String SESSION_ROLENAME = "SESSION_ROLENAME";
	public static final String SESSION_SITEID = "SESSION_SITEID";
	public static final String SESSION_SITENAME = "SESSION_SITENAME";
	public static final String SESSION_SITEGROUPNO = "SESSION_SITEGROUPNO";
	public static final String SESSION_INVERTERTYPE = "SESSION_INVERTERTYPE";
	public static final String SESSION_LASTACCESSED_TIME = "SESSION_LASTACCESSED_TIME";
	private Map sessionMap;
	private static SessionInfo userSessionInfo;

	private SessionInfo() {
	}

	// Single Tenant Class
	public static SessionInfo getSharedInstance() {
		if (userSessionInfo == null) {
			userSessionInfo = new SessionInfo();
		}
		return userSessionInfo;
	}

	public Object getSessionData(String fieldName) {
		if (sessionMap == null) {
			return null;
		}
		Object obj = sessionMap.get(fieldName);
		if (obj != null) {
			return obj;
		}
		return null;
	}

	public void putSessionData(String fieldName, Object dataValue) {
		if (sessionMap == null) {
			sessionMap = new HashMap();
		}
		sessionMap.put(fieldName, dataValue);
	}

	public void removesessionData(String fieldName) {
		if (sessionMap == null) {
			sessionMap = new HashMap();
		}
		sessionMap.remove(fieldName);
	}

	public void clearSessionMap() {
		if (sessionMap == null) {
			sessionMap = new HashMap();
		}
		sessionMap.clear();
	}

	public Map getSessionDataMap() {
		return sessionMap;
	}

	public String toString() {
		StringBuffer ret = new StringBuffer();
		System.err.println("SESSION PARTY ID :: " + SESSION_PARTYID);
		ret.append("SESSION_PARTYID='" + SESSION_PARTYID + "'");
		// ret.append("SESSION_STRIP_BY_ORG_ID='" + SESSION_STRIP_BY_ORG_ID +
		// "'");
		// ret.append("SESSION_FIRSTNAME='" + SESSION_FIRSTNAME + "'");
		ret.append("sessionMap='" + sessionMap + "'");
		System.err.println("SESSION MAP:: " + sessionMap.toString());
		return ret.toString();
	}

	public static void setUserSessionInfo(SessionInfo pUserSessionInfo) {
		userSessionInfo = pUserSessionInfo;
	}

	public static void populateUserSessionInfo(SessionInfo pUserSessionInfo) {
		if (pUserSessionInfo != null) {
			Map sessionDataMap = pUserSessionInfo.getSessionDataMap();
			if (sessionDataMap != null)
				userSessionInfo.getSessionDataMap().putAll(sessionDataMap);
		}
	}
}
